/*
 * Copyright 2016-2018 TVI Go Easy.
 * Created on 2018/1/18 16:31
 */
package com.tvi.cloud.oauth2.controller;

import org.springframework.http.MediaType;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 请在此写下该类的说明
 *
 * @author mechanic
 */
@RestController
public class OAuth2Controller {
    @RequestMapping(value = { "/user" }, produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String, Object> user(OAuth2Authentication user) {
        Map<String, Object> userInfo = new HashMap<>();
        userInfo.put("user", user.getUserAuthentication().getPrincipal());
        userInfo.put("authorities", AuthorityUtils.authorityListToSet(user.getUserAuthentication().getAuthorities()));
        return userInfo;
    }
}
